package com.cc.allexception;

import com.cc.allreturn.AjaxReturnBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.HandlerMethod;

/**
 * @User c.c
 * @Since 2023/5/12
 * @Time 11:05
 * @Description
 */
@ControllerAdvice
@RestController
@Slf4j
public class GableException {
  @ExceptionHandler(RuntimeException.class)
  public AjaxReturnBean<String> handlerError(RuntimeException ex, HandlerMethod hm) {


    System.out.println("统一异常处理");
    //异常信息
    log.info(ex.getMessage());
    //哪个类下
    log.info(hm.getBean().getClass().toString());
    //在哪个方法的
    log.info(hm.getMethod().getName());
    ex.printStackTrace();
    return AjaxReturnBean.createError(ex.getMessage());
  }

}
